/**
 * 
 */
package com.geekteam.masterenglish.Adapter;

import android.content.Context;
import android.content.res.TypedArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.geekteam.masterenglish.R;

/**
 * @author MTROL
 *
 */
public final class NavigationListAdapter extends BaseAdapter implements SpinnerAdapter {

	private LayoutInflater mLayoutInflater;
	private TypedArray     mTitles;
	
	public NavigationListAdapter(Context context, TypedArray titles){
		mLayoutInflater = LayoutInflater.from(context);
		mTitles = titles;
	}
	
	@Override
	public int getCount() {
		return mTitles.length();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return mTitles.getResourceId(position, 0);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			convertView = mLayoutInflater.inflate(R.layout.item_navigation, parent, false);
		}
		
		TextView title = (TextView) convertView.findViewById(R.id.title_navigation);
		title.setText(mTitles.getString(position));
		
		return convertView;
	}
	
	@Override
	public View getDropDownView(int position, View convertView,
			ViewGroup parent) {
		if(convertView==null){
			convertView = mLayoutInflater.inflate(R.layout.dropdown_navigation, parent, false);
		}
		
		TextView title = (TextView) convertView.findViewById(R.id.dropdown_title_navigation);
		title.setText(mTitles.getString(position));
		
		return convertView;
	}
}
